// pages/show/checkList/checkList.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    checkDataList: [],
    ifName: false,
    id:'',
    status: '',
    extfeild: '',
    flag: true,
    showNoResult:false
  },

  onLoad: function (options) {
    this.getCheckingList();
  },

  onShow:function(){
    this.getCheckingList();
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
  */
  onPullDownRefresh: function () {
    var page = getCurrentPages().pop();
    if (page == undefined || page == null) return;
    page.onLoad();
    wx.stopPullDownRefresh();
  },

  // 获取审核列表  得到是未审核的桥梁
  getCheckingList: function () {
    var that = this;
    wx.showLoading({
      title: '加载中',
    });
    wx.request({
      url: app.globalData.siteUrl +'/bridge/searchBridgeList',
      method: 'post',
      header: {
        "X-Token": wx.getStorageSync("openId"),
        "Content-Type": "application/x-www-form-urlencoded",
      },
      data: {
        "status": 4
      },
      success: function (res) {
        if (res.data.model != null) {
          if (res.data.model.length<=0){
            that.setData({
              checkDataList: res.data.model,
              showNoResult:true
            });
          }else{
            that.setData({
              checkDataList: res.data.model,
              showNoResult: false
            });
          }
        } else {
          that.setData({
            checkDataList:[],
            showNoResult: true
          });
        }  
      },
      complete: function () {
        wx.hideLoading();
      }
    });
  },

  // 跳转到审核详细信息页面
  kindToggle(e) {
    let activeCategoryId = this.data.activeCategoryId;
    var bridgeId = e.currentTarget.dataset.id;

    let bridges = this.data.checkDataList; 
    let bridgeInfo = bridges.find(function (bridge) {
      return bridge.id === bridgeId;
    });
    var fullUrl = "/pages/rights/checkList/checkListDetails/checkListDetails";
    var args = "?bridgeInfo=" + JSON.stringify(bridgeInfo);
    this.navigation(fullUrl, args);
  },

  // 使用navigateBack
  navigation: function (pageUrl, args) {
    var cps = getCurrentPages();
    var delta = 0;
    for (var i = cps.length - 1; i >= 0; i--) {
      if ("/" + cps[i].route == pageUrl) {
        if (delta == 0) {
          return;
        }
        wx.navigateBack({
          delta: delta
        });
        return;
      }
      delta++;
    }
    wx.navigateTo({
      url: pageUrl + args,
    })
  }

})